/**
 * 给视觉观提供的压缩设置类型
 */
export enum SensorCompressionType {
	/**
	 * 没有，使用float arrays
	 */
	None,

	/**
	 * PNG 格式，使用二进制格式保存
	 */
	PNG,
}

/**
 * 观察者们使用的压缩数据规范，
 */
export class CompressionSpec {
	private _sensorCompressionType: SensorCompressionType;
	public get sensorCompressionType(): SensorCompressionType {
		return this._sensorCompressionType;
	}

	private _compressedChannelMapping?: number[];
	public get compressedChannelMapping(): number[] | undefined {
		return this._compressedChannelMapping;
	}

	constructor(sensorCompressionType: SensorCompressionType, compressedChannelMapping?: number[]) {
		this._sensorCompressionType = sensorCompressionType;
		this._compressedChannelMapping = compressedChannelMapping;
	}

	static default(): CompressionSpec {
		return new CompressionSpec(SensorCompressionType.None);
	}

	/**
	 * 检测压缩通道映射是否是普通的，如果是这样的就不用发给训练器（trainer）
	 * @returns
	 */
	isTrivialMapping(): boolean {
		const mapping = this.compressedChannelMapping;
		if (!mapping) {
			return true;
		}

		//check if mapping equils zero mapping
		if (mapping.length == 3 && mapping.every((m) => m == 0)) {
			return true;
		}

		for (let i = 0; i < mapping.length; i++) {
			const element = mapping[i];
			if (element != i) {
				return false;
			}
		}
		return true;
	}
}
